$("#form-${model.modelL}-add").validate({
	rules:{
#foreach($field in $fieldList)
#if($field.isPk != "Y")
#if(!$field.nullable)
		${field.field}:{
			required:true
		},
#elseif($field.validate=="email")
		${field.field}:{
			required:true,
			 email:true
		},
#elseif($field.validate=="mobile")
		${field.field}:{
			required:true,
			isPhone:true
		},
#elseif($field.validate=="number")
		${field.field}:{
			required:true,
			number:true
		},
#elseif($field.validate=="date")
		${field.field}:{
			required:true,
			dateISO:true
		},
#elseif($field.validate=="integer")
		${field.field}:{
			required:true,
			digits:true
		},
#elseif($field.validate=="url")
		${field.field}:{
			required:true,
			url:true
		},
#end
#end
#end
	},
	submitHandler:function(form){
		add();
	}
});

function add() {
#foreach($field in $fieldList) 
#if($field.isPk != "Y"&&${field.inputType}!="none")
#if(${field.inputType}=="select")
	var ${field.field} = $("#${field.field} option:selected").val();
#elseif(${field.inputType}=="radio")
	var ${field.field} = $("input[name='${field.field}']").is(':checked') == true ? 0 : 1;
#elseif(${field.inputType}=="checkbox")
	var ${field.field} = $.getCheckeds("${field.field}");
#elseif(${field.inputType}=="htmleditor")
	var ${field.field} = ue_${field.field}.getContent();
#elseif(${field.inputType}=="textarea")
	var ${field.field} = $("#${field.field}").val();
#else
	var ${field.field} = $("input[name='${field.field}']").val();
#end
#end
#end  
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx + "${model.modulePackage}/${model.modelL}/save",
		data : {
#foreach($field in $fieldList) 
#if($field.isPk != "Y"&&${field.inputType}!="none")
			"${field.field}": ${field.field},
#end
#end
		},
		async : false,
		error : function(request) {
			$.modalAlert("系统错误", modal_status.FAIL);
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
					$.parentReload();
				});
			} else {
				$.modalAlert(data.msg, modal_status.FAIL);
			}

		}
	});
}
#foreach($field in $fieldList)
#if(${field.inputValueOne} == "sys_dept")
/*用户管理-新增-选择部门树*/
function selectDeptTree() {
	var treeId = $("#treeId").val();
	var deptId = treeId == null || treeId == "" ? 100 : treeId;
	var url = ctx + "system/dept/selectDeptTree/" + deptId;
    layer_show("选择部门", url, '380', '380');
}
#elseif(${field.inputType}=="file")
$(document).ready(function(){
 
    ${field.field}_fileinputlist();
});

/** 初始化文件框*/
function ${field.field}_fileinputlist(){
    $('#${field.field}_uploadfile').fileinput({
        language: 'zh', //设置语言
        showPreview: false,//是否显示预览,不写默认为true
        showUpload: false, //是否显示上传按钮,跟随文本框的那个
        showRemove : true, //显示移除按钮,跟随文本框的那个
        showCaption: true,//是否显示标题,就是那个文本框
        uploadAsync : false, //默认异步上传
        elErrorContainer: '#upload-file-errors',
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        maxFileSize: 102400,      //单位为kb，如果为0表示不限制文件大小
        enctype: 'multipart/form-data',
        dropZoneTitle: '拖拽文件到这里 &hellip;<br>仅仅支持单个文件同时上传',//重新定义提示
        msgFilesTooMany: '选择上传的文件数量({n}) 超过允许的最大数值{m}！',
//        allowedFileExtensions: ["xls", "xlsx"],
        uploadUrl: ctx + "file/uploadImg",
    });
}

/*图片上传*/
function ${field.field}_fileUpload() {
    //文件默认上传方法,传ID:uploadfile
    $('#${field.field}_uploadfile').fileinput("upload");
    //同步上传错误处理
    $('#${field.field}_uploadfile').on('filebatchuploaderror', function(event, data, msg) {
        // get message
        $.modalAlert(msg, "error");
        //重置
        $('#${field.field}_uploadfile').fileinput("clear");
        $('#${field.field}_uploadfile').fileinput("reset");
        $('#${field.field}_uploadfile').fileinput('refresh');
        $('#${field.field}_uploadfile').fileinput('enable');
    });
    //同步上传后从后台返回结果
    $('#${field.field}_uploadfile').on('filebatchuploadsuccess', function(event, data, previewId, index) {
        var result = data.response;
        if (result.code == 0) {
             
            $.modalAlert(result.msg,"success"); 
            $('#${field.field}').val(result.avatar);
            $('#${field.field}_image').attr("src","/profile/"+result.avatar);   
        } else {
            $.modalAlert(result.msg, "error");
            //重置
            $('#${field.field}_uploadfile').fileinput("clear");
            $('#${field.field}_uploadfile').fileinput("reset");
            $('#${field.field}_uploadfile').fileinput('refresh');
            $('#${field.field}_uploadfile').fileinput('enable');
        }
    });

}
#end
#end